//
//  UserLocationManager.m
//  iFoundIt
//
//  Created by Navid Shariat on 27/05/10.
//  Copyright 2010 QUT. All rights reserved.
//

#import "UserLocationManager.h"


@implementation UserLocationManager
@synthesize locationManager,currentLocation;

-(void) deallc{
	[locationManager release];
	[currentLocation release];
	[super dealloc];
}

- (id)init{
	CLLocationManager *locMan = [[CLLocationManager alloc] init];
	[locMan setDelegate:self];
	[locMan setDistanceFilter:10.0f];
	[locMan setDesiredAccuracy:kCLLocationAccuracyBest];
	[self setLocationManager:locMan];
	[locMan release];
	// Once configured, the location manager must be "started".
	[[self locationManager] startUpdatingLocation];	
	[super init];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
	[manager stopUpdatingLocation];	
	[self setCurrentLocation:newLocation];
}

- (CLLocation *)currentLocation{
	if (currentLocation!=nil)
		return currentLocation;
	int i=0;
	do{
		i++;
		sleep(1);
	} while(i<10 && currentLocation==nil);
	return currentLocation;
}



@end
